package com.yjj.im.Utils;

import org.json.JSONObject;

import java.util.ArrayList;
import com.yjj.im.bean.Company.CompanyBeann;

/**
 * Created by n on 2018/8/26.
 */

public class GsonFomater {

    public static String format(String json) {
        try {
            JSONObject object = new JSONObject(json);
            String tempJson = object.getString("json");
            return tempJson;
        } catch (Exception e) {
            return "";
        }
    }

    public static <T> T format(String json, Class<T> clazz) {
        try {
            JSONObject object = new JSONObject(json);
//            String tempJson = object.getString("data");
//            tempJson = tempJson.replace("$$", "+");
//            tempJson = tempJson.replace("@@", "/");
//            String temp = AES.decodeByBase64(tempJson);
            return GsonUtil.fromJson(json, clazz);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }

    public static ArrayList<CompanyBeann> parsedata(String json){
        ArrayList<CompanyBeann> list = new ArrayList<>();
        if(json != null){
            json = json.substring(1,json.length()-1);
            String[] s = json.split(",");
            if(s != null){
                for(int i = 0;i <s.length;i++){
                   String  strS = s[i];
                   String[] stringData = strS.split(":");
                        String id = stringData[0];
                        String name = stringData[1];
                        CompanyBeann company = new CompanyBeann();
                        company.setId(id);
                        company.setName(name);
                        list.add(company);
                }
            }
        }else {
            return null;
        }
        return list;
    }

}
